<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书管理员注册</title>
    <link href="css/createLibrabian.css" rel="stylesheet">
</head>
<body>
<div class="create">
    <h2>图书管理员注册</h2>
    <form>
        <div class="inp">
            <div><input id="username" type="text" placeholder="用户名" class="txt1"></div>
            <div><input id="nickname" type="text" placeholder="昵称" class="txt2"></div>
            <div><input id="password" type="password" placeholder="密码" class="txt2"></div>
            <div><input id="password_again" type="password" placeholder="确认密码" class="txt2" onblur="psw_check()"></div>
        </div><br/>
        <div class="btn"><input id="submit" type="submit" value="注册" class="btn1"></div>
    </form>
</div>
</body>
<script src="js/jquery.js"></script>
<script src="js/md5.js"></script>
<script src="js/admin.js"></script>
<script>
    $("#submit").click(function (){
        var username=$("#username").val();
        var nickname=$("#nickname").val();
        var pwdsrc=$("#password").val();
        var password=hex_md5(pwdsrc);
        var token=sessionStorage.getItem("token");//从sessionStorage中提取token
        if(username==""||nickname==""||password=="d41d8cd98f00b204e9800998ecf8427e"){//检查输入是否为空
            alert("必填项不能为空！");//此处password判空字符串为""进行md5加密后
            return ;
        }
        var data={//作为申请时携带的对象
            "username":username,
            "nickname":nickname,
            "password":password,
            "enabled":true
        }
        $.ajax({
            url:"http://lenjon.top:9090/admin/addAdmin",
            type:"POST",
            async:false,
            headers:{
                "Content-Type": "application/json;charset=utf8",
                'Accept': '*/*',
                "token":token//添加token作为请求凭证
            },
            data:JSON.stringify(data),
            dataType:"json",
            success:function (data){
                if(data.code==200){//请求成功
                    alert("图书管理员添加成功！");
                    window.open("admin_1.html");//返回管理界面
                }
                else {
                    alert("添加失败！");
                }
            }
        })
    })
</script>
</html>